import { app, Tray, Menu, nativeImage } from 'electron'
import path from 'node:path'
import { browserWindowManager } from './browserManager'

const iconPath = nativeImage.createFromPath(path.join(process.resourcesPath, 'asset/logo.png'))

class SystemTray {

  tray: Tray | null = null;

  init() {
    if (this.tray) return
    this.tray = new Tray(iconPath)

    const contextMenu = Menu.buildFromTemplate([
      {
        label: '显示主窗口',
        click: () => {
          browserWindowManager.getBrowserWindow("MAIN").show()
        }
      },
      {
        label: '退出应用',
        click: () => {
          app.quit()
        }
      },
    ])

    this.tray.setToolTip('RPA-IDE') // 设置鼠标悬停时显示的提示信息
    this.tray.setContextMenu(contextMenu)

    this.tray.on('click', () => {
      browserWindowManager.getBrowserWindow("MAIN").show()
    })
  }

  getTray() {
    return this.tray
  }

}
// 系统托盘
export const systemTray = new SystemTray()
